<template>
  <el-dialog
    @close="yfkdkqrCancel('yfkdkqrRuleForm')"
    :close-on-click-modal="false"
    title="预付款确认"
    :visible.sync="yfkdkqrVisible"
    width="600px"
  >
    <div class="scroll-view">
      <el-descriptions :column="1" border>
        <el-descriptions-item label="预付款金额" v-if="fieldShowFunc('amount_collected')">{{ yfkpzData.amount_collected?yfkpzData.amount_collected+'元':'--' }}</el-descriptions-item>
        <el-descriptions-item label="收款账户" v-if="fieldShowFunc('receiving_account')">{{ yfkpzData.receiving_account_name }}</el-descriptions-item>
        <el-descriptions-item label="收款凭证" v-if="fieldShowFunc('voucher_file')">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name" v-for="(item, index) in yfkpzData.payment_voucher" :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <el-form
        :model="yfkdkqrRuleForm"
        :rules="yfkdkqrRules"
        ref="yfkdkqrRuleForm"
        label-position="top"
      >
        <el-form-item label="" prop="radio">
          <el-radio-group v-model="yfkdkqrRuleForm.radio">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            :rows="4"
            class="input-box"
            v-model="yfkdkqrRuleForm.remark"
            type="textarea"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>

    <span slot="footer">
      <el-button
        type="primary"
        @click="yfkdkqrSubmit('yfkdkqrRuleForm')"
        :disabled="diaLoading"
        :loading="diaLoading"
        >提交</el-button
      >
      <el-button @click="yfkdkqrCancel('yfkdkqrRuleForm')">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    yfkpzData: {
      required: false,
    },
    fieldList:{
      required: false,
    }
  },
  data() {
    return {
      yfkdkqrVisible: false,
      yfkdkqrRules: {},
      yfkdkqrRuleForm: {
        voucher_id: "",
        remark: "",
        radio: 1,
      },
      diaLoading: false,
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      this.yfkdkqrVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() {},
  methods: {
    // 判断是否显示
    fieldShowFunc(field) {
      let fieldList = this.fieldList;
      return fieldList[field] == undefined ? true : fieldList[field];
    },
    // 预付款确认
    yfkdkqrCancel(formName) {
      this.yfkdkqrRuleForm = {
        voucher_id: "",
        remark: "",
        radio: 1,
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    yfkdkqrSubmit(formName) {
      let yfkdkqrRuleForm = this.yfkdkqrRuleForm;
      console.log(yfkdkqrRuleForm, "预付款确认参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          if (yfkdkqrRuleForm.radio == 2) {
            projectApi
              .financialRejection({
                project_id: this.project_id,
                remark: yfkdkqrRuleForm.remark,
              })
              .then((res) => {
                this.diaLoading = false;
                console.log(res, "财务驳回");
                if (res.code == 200) {
                  this.$emit("onSuccess", true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          projectApi
            .confirmAdvancePayment({
              project_id: this.project_id,
              voucher_id: "",
              remark: yfkdkqrRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "预付款确认");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>